<?php

	class Framework{
		public static function run(){
			self::init();
			self::autoload();
			self::dispatch();
		}
		public static function init(){
			define('DS',DIRECTORY_SEPARATOR);
			define('ROOT',getcwd().DS);
			define('APP_PATH',ROOT.'application'.DS);
			define('FRAMEWORK_PATH',ROOT.'framework'.DS);
			define('PUBLIC_PATH',ROOT.'public'.DS);

			define('CORE_PATH',FRAMEWORK_PATH.'core'.DS);
			define('DB_PATH',FRAMEWORK_PATH.'database'.DS);
			define('LIB_PATH',FRAMEWORK_PATH.'libraries'.DS);

			define('UPLOAD_PATH',PUBLIC_PATH.'uploads'.DS);

			define('PALTFORM',isset($_REQUEST['p'])?$_REQUEST['p']:'back');
			define('MODEL',isset($_REQUEST['m'])?$_REQUEST['m']:'Index');
			define('ACTION',isset($_REQUEST['a'])?$_REQUEST['a']:'Index');

			define('MODEL_PATH',APP_PATH.PALTFORM.DS);

			require_once DB_PATH.'Mysql.class.php';
			require_once CORE_PATH.'Model.class.php';
			require_once CORE_PATH.'Loader.class.php';
			session_start();
		}
		public static function autoload(){
			spl_autoload_register(array(__CLASS__,'load'));
		}
		public static function load($className){
			if(substr($className,-5) == 'Model'){
				require_once MODEL_PATH."$className.class.php";
			}
		}
		public static function dispatch(){
			$model_name = MODEL.'Model';
			$action_name = ACTION.'Action';
			$model = new $model_name;
			$model->$action_name();
		}
	}